import java.util.Scanner;

public class SynchronizedDemo {
 static class Couner{
     public volatile int flag=0;
 }

    public static void main(String[] args) {
        Couner couner=new Couner();
        Thread t1=new Thread(()->{
            while (couner.flag==0){

            }
            System.out.println("循环结束");
        });
        Thread t2=new Thread(()->{
            Scanner scanner=new Scanner(System.in);
            System.out.println("输入一个数");
            couner.flag=scanner.nextInt();
        });
        t2.start();
        t1.start();
    }

    }

